﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Golf.WebUI.GolfCart
{
    public partial class CartDel : System.Web.UI.Page
    {
        public string ProId
        {
            get
            {
                if (Request.Params["id"] != null && Request.Params["id"].ToString() != "")
                {
                    return Request.Params["id"].ToString().Trim();
                }
                else
                {
                    return "";
                }
            }
        }
        /// <summary>
        /// 清空购物车
        /// </summary>
        public string action
        {
            get
            {
                if (Request.Params["action"] != null && Request.Params["action"].ToString() != "")
                {
                    return Request.Params["action"].ToString().Trim();
                }
                else
                {
                    return "";
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ProId != "")
            {
                Response.Buffer = true;//清理缓存
                Response.ExpiresAbsolute = DateTime.Now.AddHours(-1);
                Response.Expires = 0;
                Response.CacheControl = "no-cache";
                //删除购物车商品
                Response.Write(DelCart());
            }
            if (action != "" && action == "ClearBasket")
            {
                Response.Buffer = true;//清理缓存
                Response.ExpiresAbsolute = DateTime.Now.AddHours(-1);
                Response.Expires = 0;
                Response.CacheControl = "no-cache";
                CookiesHelper.ClearCookie("GOLF");
                Response.Write("delcart|");
            }
        }

        public string DelCart()
        {
            if (Request.Cookies["GOLF"] != null)
            {
                HttpCookie ShopCart = Request.Cookies["GOLF"];
                ShopCart.Values.Remove(ProId.ToString());
                if (ShopCart.Values.Count > 0)
                {
                    ShopCart.Expires = DateTime.Now.AddDays(30);
                }
                else
                {
                    ShopCart.Expires = DateTime.Now.AddDays(-1);
                }
                Response.Cookies.Add(ShopCart);
                return "delcart|";
            }
            else
            {
                return "error";
            }
        }
    }
}
